var express = require('express')
var router = express.Router()
const { getAll, getOne, exec } = require('../../db/index')

router.get('/number', async (req, res) => {
  let sql = `select count(*) total,t.category_id,t2.type from blog_articles as t,blog_category as t2 where t.category_id =t2.id GROUP BY t.category_id`
  const data = await getAll(sql)
  res.send({
    code: 0,
    message: '获取成功',
    result: data,
  })
})

// 查询不同分类下的点击量的总数
router.get('/clicknumber', async (req, res) => {
  let sql = `select SUM(t1.click) value,t2.type name from blog_articles as t1,blog_category as t2 where t1.category_id = t2.id GROUP BY t1.category_id`
  const data = await getAll(sql)
  res.send({
    code: 0,
    message: '查询成功',
    result: data,
  })
})

module.exports = router
